<template>
  <div class="app-wrapper">
    <div class="sidebar-container" :class="{ 'is-collapse': isCollapse }">
      <div class="sidebar-toggle" @click="toggleSidebar">
        <el-icon v-if="isCollapse"><Expand /></el-icon>
        <el-icon v-else><Fold /></el-icon>
      </div>
      <div class="sidebar-wrapper">
        <app-sidebar :is-collapse="isCollapse" />
      </div>
    </div>
    
    <div class="main-container">
      <app-header />
      
      <div class="app-main">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
import { Expand, Fold } from '@element-plus/icons-vue'
import AppHeader from '@/components/layout/Header.vue'
import AppSidebar from '@/components/layout/Sidebar.vue'

export default {
  name: 'Layout',
  components: {
    AppHeader,
    AppSidebar
  },
  setup() {
    const isCollapse = ref(false)
    
    const toggleSidebar = () => {
      isCollapse.value = !isCollapse.value
    }
    
    return {
      isCollapse,
      toggleSidebar,
      Expand,
      Fold
    }
  }
}
</script>

<style scoped>
.app-wrapper {
  position: relative;
  height: 100vh;
  width: 100%;
  display: flex;
  overflow: hidden;
}

.sidebar-container {
  background-color: #304156;
  width: 210px;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  overflow: hidden;
  transition: width 0.3s;
  z-index: 1001;
  display: flex;
  flex-direction: column;
}

.sidebar-container.is-collapse {
  width: 64px;
}

.sidebar-toggle {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #bfcbd9;
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-wrapper {
  flex: 1;
  overflow: hidden;
}

.main-container {
  flex: 1;
  margin-left: 210px;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: calc(100% - 210px);
  transition: margin-left 0.3s, width 0.3s;
  overflow: hidden;
}

.sidebar-container.is-collapse + .main-container {
  margin-left: 64px;
  width: calc(100% - 64px);
}

.app-main {
  flex: 1;
  padding: 0;
  background-color: #f5f7fa;
  overflow: hidden;
}
</style> 